package com.codebo.homiematchbackend.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codebo.homiematchbackend.model.entity.User;
import com.codebo.homiematchbackend.model.entity.blog.BlogComment;
import com.codebo.homiematchbackend.model.vo.BlogCommentVO;
import com.codebo.homiematchbackend.service.BlogCommentService;
import com.codebo.homiematchbackend.mapper.BlogCommentMapper;
import com.codebo.homiematchbackend.service.UserService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author 25912
* @description 针对表【blog_comment(博客评论)】的数据库操作Service实现
* @createDate 2025-09-22 17:07:59
*/
@Service
public class BlogCommentServiceImpl extends ServiceImpl<BlogCommentMapper, BlogComment>
    implements BlogCommentService{

    @Resource
    private UserService userService;

    @Override
    public BlogCommentVO getBlogCommentVO(BlogComment blogComment)
    {
        BlogCommentVO blogCommentVO = new BlogCommentVO();
        BeanUtil.copyProperties(blogComment, blogCommentVO);
        User user = userService.getById(blogComment.getUserId());
        blogCommentVO.setUsername(user.getUsername());
        blogCommentVO.setUserAvatar(user.getUserAvatar());
        return blogCommentVO;
    }

    @Override
    public List<BlogCommentVO> getBlogCommentVOList(List<BlogComment> blogComments)
    {
        return blogComments.stream().map(this::getBlogCommentVO).collect(Collectors.toList());
    }
}




